<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>组织管理/编辑页面</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">
    <link rel="stylesheet" href="${ctx}/iconfont/iconfont.css"/>
    <link rel="stylesheet" href="${ctx}/css/public.css">
    <script type="text/javascript">
        var __ctx = "${ctx}";
    </script>
</head>
<body>
    <form class="layui-form  updataFormOrg" action="" lay-filter="updataFormOrg" onsubmit="return false">
        <!--隐藏域属性配置 -->
        <input type="hidden" name="orgId" class="orgId">
        <input type="hidden" name="demId" class="demId">
        <input type="hidden" name="orgSupId" class="orgSupId">
        <input type="hidden" name="tenantId" class="tenantId">
        <input type="hidden" name="orgPathname" class="orgPathname">
        <input type="hidden" name="path" class="path">
        <input type="hidden" name="depth" class="depth">
        <!---------------------------------->

        <div class="layui-form-item">
            <label class="layui-form-label">上级组织:</label>
            <div class="layui-input-block pidOrg"></div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">组织名称:<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="orgName" placeholder="请输入组织名称"
                       autocomplete="off" class="layui-input" maxlength="32" lay-verify="required|names">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">组织代码:<span style="color:red" id="code_tip">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="code" placeholder="请输入组织代码" id="orgCode"
                       autocomplete="off" class="layui-input" maxlength="32" lay-verify="">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">组织类型:<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <select name="orgType">
                    <option value="0">集团</option>
                    <option value="1">公司</option>
                    <option value="2">部门</option>
                    <option value="3">其他组织</option>
                </select>
            </div>
        </div>


        <div class="layui-form-item">
            <label class="layui-form-label">是否租户:</label>
            <div class="layui-input-block" id="isTenant_div">
                <input type="checkbox" id="isTenant" name="isTenant" lay-skin="primary" lay-filter="isTenantcheck">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">编制人数:</label>
            <div class="layui-input-block">
                <input type="text" name="orgStaff" placeholder="请输入编制人数"
                       autocomplete="off" class="layui-input" maxlength="32" lay-verify="staffing">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">序列:</label>
            <div class="layui-input-block">
                <input type="text" name="sn" placeholder="请输入序列"
                       autocomplete="off" class="layui-input" lay-verify="sort">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">组织描述:</label>
            <div class="layui-input-block">
                <textarea name="orgDesc" class="layui-textarea" placeholder="请输入组织描述" maxlength="500"></textarea>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;padding-left: 25px">
                <button  lay-submit lay-filter="formDemo" class="layui-btn">保存</button>
                <button class="layui-btn cancelFrom layui-btn-danger">取消</button>
        </div>
    </form>

<script src="${ctx}/public/component.js" type="text/javascript"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index', 'setter', 'commons', 'form', 'jquery', 'layer'], function () {
            var form = layui.form,
                layer = layui.layer,
                commons = layui.commons,$=layui.jquery,
                setter = layui.setter;
            form.verify(commons.formVerify);
            var orgId = '${orgId}';
            var pid = '${pid}';
            var isTenant = '${isTenant}';
            if(pid==setter.dimensionVariable){
                $("#isTenant").attr("checked",true);
                $("#isTenant").attr("disabled",true);
            }
            if(isTenant==0){
                $("#isTenant").attr("disabled",true);
            }
            // 获取本级组织data
            $.ajax({
                type: 'get',
                url: serverPath.systemPath + setter.sysLinkPath + "sysOrg/get",
                dataType:"json",
                data: {
                    orgId: pid || orgId
                },
                success: function (data) {
                    var result = data.data;
                    $('.demId').val(setter.dimensionVariable);
                    if (pid) {
                        if(null!=result) {
                            $('.pidOrg').html(result.name);
                        }
                        $('.orgSupId').val(pid);
                    } else {
                        if (null != result) {
                            $('.pidOrg').html(result.orgSupName);
                        }
                        $('.orgSupId').val(setter.dimensionVariable);
                        form.val('updataFormOrg', result);
                        $("#isTenant").attr("disabled",true);
                        $("#orgCode").attr("disabled",true);
                    }
                }
            });
            form.render();

            //监听提交
            form.on('submit(formDemo)', function (data) {
                data.field.isTenant = data.field.isTenant ? '1' : '0';
                $.ajax({
                    url: serverPath.systemPath + setter.sysLinkPath + "sysOrg/add",
                    type: "POST",
                    dataType:"json",
                    data: data.field,
                    success: function (data) {
                        if (commons._filterRecord(data)) {
                            layer.alert(data.msg, function (index) {
                                layer.close(index);
                                $('#btn-refresh', window.parent.document).click();
                                parent.layer.close(parent.layer.getFrameIndex(window.name));
                            });
                        } else {
                            layer.alert(data.msg);
                        }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                        layer.alert("保存失败！" + XMLHttpRequest.status);
                    },
                });
            });
            $(".cancelFrom").click(function () {
                parent.layer.close(parent.layer.getFrameIndex(window.name))
            });
            form.on('checkbox(isTenantcheck)', function(data){
                //console.log(data.elem); //得到checkbox原始DOM对象
                //console.log(); //是否被选中，true或者false
                //console.log(data.value); //复选框value值，也可以通过data.elem.value得到
                //console.log(data.othis); //得到美化后的DOM对象
                var valid=$("#orgCode").attr("lay-verify");
                if(data.elem.checked){
                    $("#orgCode").attr("lay-verify","orgCode|required");
                }else{
                    $("#orgCode").attr("lay-verify","");
                }
            });

            if($("#isTenant").is(':checked')){
                $("#code_tip").show();
            }else {
                $("#code_tip").hide();
            }

            $("#isTenant_div").click(function(){

                if($("#isTenant").is(':checked')){
                    $("#code_tip").show();
                }else {
                    $("#code_tip").hide();
                }
            });


        });
    </script>
    <style>
        /* sysOrg/updata */
        .updataFormOrg {
            width: 500px;
            height: 539px;
            overflow: auto;
            margin-top: 9px;
        }

        .updataFormOrg .pidOrg {
            height: 36px;
            line-height: 36px;
        }

    </style>
</body>
</html>